package cf.huzpsb.bcgod;

import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

public class PointsCMD extends Command {
    public PointsCMD(String name, String permission, String... aliases) {
        super(name, permission, aliases);
    }

    public void execute(CommandSender sender, String[] args) {
        if (!(sender instanceof ProxiedPlayer)) {
            sender.sendMessage("§c后台无法使用此命令");
            return;
        } else if (((ProxiedPlayer) sender).getServer().getInfo().getName().equalsIgnoreCase(Main.login)) {
            sender.sendMessage("§c登录区域禁止使用!");
            return;
        }
        int nh;
        if (args.length != 1) {
            if (Main.horncfg.contains(sender.getName())) {
                nh = Main.horncfg.getInt(sender.getName());
                sender.sendMessage("§a[huzpsb]>你现在的欢乐券个数为:" + nh);
            } else {
                sender.sendMessage("§c错误:你现在没有欢乐券.");
            }
        } else {
            int i;
            try {
                i = Integer.parseInt(args[0]);
            } catch (Exception e) {
                sender.sendMessage("§c参数错误.");
                return;
            }
            if (Main.horncfg.contains(sender.getName())) {
                nh = Main.horncfg.getInt(sender.getName());
            } else {
                sender.sendMessage("§c错误:你现在没有欢乐券.");
                return;
            }
            nh -= i;
            if (nh < 0) {
                sender.sendMessage("§c错误:你没有足够多的欢乐券.");
            }
            if (nh == 0) {
                Main.horncfg.set(sender.getName(), null);
            } else {
                Main.horncfg.set(sender.getName(), nh);
            }
            sender.sendMessage("§a[huzpsb]>氪金 " + i + " 成功!你现在的欢乐券个数为: " + nh);
            ((ProxiedPlayer) sender).chat("/spoins " + i);
        }
    }
}
